import Vue from 'vue'
import VueRouter from 'vue-router'
// import Home from '../views/Home.vue'
// import Register from '../views/Register.vue'
// import User from '../views/User.vue'

const Home = () => import('../views/Home')
const Register = () => import('../views/Register')
const User = () => import('../views/User')
const HomeNews = () => import('../views/HomeNews')
const HomeMessage = () => import('../views/HomeMessage')
const Profile = () => import('../views/Profile.vue')
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    //路由重定向
    //redirect: '/home'
    redirect: '/home'
  },
  {
    path: '/home',
    meta:{
      title:'首页'
    },
    component: Home,
    children: [
      {
        path:'',
        redirect:'news'
      },
      {
        path: 'news',
        component: HomeNews
      },
      {
        path:'message',
        component:HomeMessage
      }
    ]
  },
  {
    path: '/about',
    meta:{
      title: '列表'
    },
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  },
  {
    path: '/register',
    meta:{
      title: '注册'
    },
    component: Register
  },
  {
    path: '/user/:userId',
    meta:{
      title: '用户'
    },
    component: User
  },
  {
    path:'/profile',
    meta:{
      title:'档案'
    },
    component:Profile
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
//全局导航守卫
router.beforeEach((to, from, next) => {
  document.title = to.matched[0].meta.title;
  //next必须写
  next()
})
export default router
